package com.getpebble.android.common.framework.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import com.getpebble.android.R;
import com.getpebble.android.common.core.trace.Trace;

public abstract class PblBaseFragment extends Fragment {
    private RelativeLayout mLoadingLayout = null;

    public abstract int getLayoutId();

    public abstract void init(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle);

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        FrameLayout baseLayout = (FrameLayout) inflater.inflate(R.layout.fragment_pbl_base, null);
        ViewGroup fragmentView = (ViewGroup) inflater.inflate(getLayoutId(), baseLayout, false);
        try {
            init(inflater, fragmentView, savedInstanceState);
        } catch (Exception e) {
            Trace.error(getClass().getSimpleName(), "Error inflating fragmentView!", e);
        }
        if (baseLayout == null) {
            throw new IllegalStateException("There is no base layout!");
        }
        if (fragmentView != null) {
            baseLayout.addView(fragmentView);
        }
        this.mLoadingLayout = (RelativeLayout) baseLayout.findViewById(R.id.grp_loading_wrapper);
        if (this.mLoadingLayout != null) {
            this.mLoadingLayout.bringToFront();
        }
        return baseLayout;
    }

    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
    }
}
